<?php

include_once($_SERVER['DOCUMENT_ROOT'] ."/include/user/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/taobao/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/mblog/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/album/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/gonglue/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/qq/inc.php");
//所有的参数
$g_cgival 	= array();
//存储中间数据 非输出数据 可以不用
$g_pro	 	= array();
//要显示的数据 输出数据
$g_show 	= array();

function check_cgi_pro()
{		
	global $g_cgival, $g_pro, $g_show, $config;
	
	cgi::both($g_cgival["p"], "p", "");
	$g_cgival["p"] = intval($g_cgival["p"]);
	
	if($g_cgival["p"] < 1) $g_cgival["p"]=1;
	
	cgi::both($g_cgival["id"], "id", "");
	$g_cgival["id"] = intval($g_cgival["id"]);
	
	cgi::both($g_cgival["pcount"], "pcount", 20);
	$g_cgival["pcount"] = intval($g_cgival["pcount"]);
	
	cgi::both($g_cgival["album_id"], "album_id", "");
	$g_cgival["album_id"] = intval($g_cgival["album_id"]);
	
	cgi::both($g_cgival["topic_id"], "topic_id", "");
	$g_cgival["topic_id"] = intval($g_cgival["topic_id"]);
	
	cgi::both($g_cgival["uid"], "uid", "");
	$g_cgival["uid"] = intval($g_cgival["uid"]);
	
}


function get_data()
{
	global $g_cgival, $g_pro, $g_show, $config;
	$g_show["channel"] = "mblog";
	$pcount = $g_cgival["pcount"];
	$p = $g_cgival["p"];
	$id= $g_show["id"] = $g_cgival["id"] ;
	$need_pic = 13;
	
	if(!$id)
	{
		throw new Exception("id不能为空！");
	}
	//登录相关
	$user_info = new user_info();
	$is_login = $user_info->is_logined();
	
	$user_info = new user_info();
	$is_login = $user_info->is_logined();
	if($is_login)
	{
		$user_detail_info = $user_info->get_cur_user_info();
		
		$uid = $user_detail_info["uid"];
		$user_nickname = $user_detail_info["user_nickname"];
		$g_show["is_logined"] = true;
		$g_show["current_user_info"] = $user_detail_info;
	}
	
	
	$db_mblog_meinv_content = new db_mblog_meinv_content();
	$item = $db_mblog_meinv_content->get_mblog_meinv_content_item($id);
	
	$item["big_pic"] = str_replace("/bmiddle/","/large/",$item["pic"]);
	$item["mw690_pic"] = str_replace("/bmiddle/","/mw690/",$item["pic"]);
	$item["pic_small"] = str_replace("/bmiddle/","/thumb150/",$item["pic"]);
	$create_uid = $item["create_uid"];
	
	$db_mblog_meinv_content = new db_mblog_meinv_content();
	$big_list = $db_mblog_meinv_content->get_mblog_pubu_list_biger_by_topic_and_create_time(1,$need_pic+1,$item["topic_id"],$item["create_time"],$g_cgival["uid"]);
	
	foreach($big_list as $key => $value)
	{
		if($value["id"] == $id)
		{
			unset($big_list[$key]);
			continue;
		}
		$big_list[$key]["pic_small"] = str_replace("bmiddle","thumb150",$value["pic"]);
		
	}
	
	
	$db_mblog_meinv_content = new db_mblog_meinv_content();
	$small_list = $db_mblog_meinv_content->get_mblog_pubu_list_smaller_by_topic_and_create_time(1,$need_pic+1,$item["topic_id"],$item["create_time"],$g_cgival["uid"]);
	foreach($small_list as $key => $value)
	{
		if($value["id"] == $id)
		{
			
			unset($small_list[$key]);
			continue;
		}
		$small_list[$key]["pic_small"] = str_replace("bmiddle","thumb150",$value["pic"]);
		
	}
	
	if(count($small_list) <7)
	{
		
		$big_list= array_slice($big_list,0,$need_pic-count($small_list));
	}
	else
	{
		$big_list= array_slice($big_list,0,7);
	}
	
	$big_list = array_values($big_list);
	
	$small_list = array_reverse($small_list);
	$small_list= array_slice($small_list,count($big_list)-$need_pic);
	$small_list = array_values($small_list);
		
	
	
	
	
	
	
	$next_id = 	$big_list[0]["id"];
	
	
	if($next_id)
	{
		$url_next = "/meinv/detail_{$next_id}.html#PinActionButtons";
		
		$g_show["next"] = $url_next;
	}
	else
	{
		//没有下一个，取最老的内容
		$next_info = $db_mblog_meinv_content->get_mblog_pubu_list_biger_by_topic_and_create_time(1,1,$item["topic_id"],"",$g_cgival["uid"]);
		
		$url_prev = "/meinv/detail_{$next_info[0]["id"]}.html#PinActionButtons";
		$g_show["next"] = $url_prev;
	
	}
	
	$prev_id = 	$small_list[count($small_list)-1]["id"];
	if($prev_id)
	{
		$url_prev = "/meinv/detail_{$prev_id}.html#PinActionButtons";
		$g_show["prev"] = 	$url_prev;
	}
	else
	{
		//没有下一个，取最老的内容
		$next_info = $db_mblog_meinv_content->get_mblog_pubu_list_smaller_by_topic_and_create_time(1,1,$item["topic_id"],"",$g_cgival["uid"]);
		
		$url_prev = "/meinv/detail_{$next_info[0]["id"]}.html#PinActionButtons";
		$g_show["prev"] = $url_prev;
	}
		
	
	foreach($small_list as $key => $value)
	{
		$small_list[$key]["content"] = preg_replace("/<.*?>/","",$small_list[$key]["content"]);
	}
	foreach($big_list as $key => $value)
	{
		$big_list[$key]["content"] = preg_replace("/<.*?>/","",$big_list[$key]["content"]);
	}
	
	$g_show["small_list"] = $small_list;
	$g_show["big_list"] = $big_list;
	
	
	$item["user_info"] = $user_info->get_user_info_by_uid($create_uid);
	
	if(!$g_cgival["uid"])
	{
		$db_mblog_meinv_content = new db_mblog_meinv_content();
		$user_mblog_list = $db_mblog_meinv_content->get_mblog_pubu_list_by_topic(1,3,"",1,"",$create_uid);
		foreach($user_mblog_list as $key => $value)
		{
			
			if($value["id"] == $id )
			{
				unset($user_mblog_list[$key]);
				continue;
			}
			$user_mblog_list[$key]["pic_small"] = str_replace("bmiddle","thumb150",$value["pic"]);
		}
		$user_mblog_list = array_values($user_mblog_list);
	}
	
	$g_show["mblog_list"] = $user_mblog_list;
	$g_show["item"] =$item;

	
	
	$mod_mblog = new mod_mblog();
	
	$g_show["show_type"] = $g_cgival["show_type"];
	$g_show["topic_id"] = $g_cgival["topic_id"];
	$g_show["topic_show_type"] = $config["topic_show_type"];
	
	
	
	$db_mblog_reply = new db_mblog_reply();
	$count = $db_mblog_reply->get_count_by_mid($id);
	$list= $db_mblog_reply->get_list_by_mid($id,$p,$pcount);
	
	
	$uid_array = array();
	foreach($list as $value)
	{
		$uid_array[] = $value["create_uid"];
	}
	
	$db_user_info = new db_user_info();
	
	$user_infos= $db_user_info->get_user_list_by_uids($uid_array);
	$user_info_array =array();
	if($user_infos)
	{
		foreach($user_infos as $key => $value)
		{
			$user_info_array[$value["uid"]] = $value;
		}
	}
		
	
	$admin_uid = user_info::check_super_admin();
	
	foreach($list as $key=> $value)
	{
		if($admin_uid || $uid ==$value["create_uid"])
		{
			$list[$key]["show_del"] = 1;
		}
		else
		{
			$list[$key]["show_del"] = 0;
		}
		$list[$key]["user_info"] = $user_info_array[$value["create_uid"]];
	}
	
	
	$g_show["count"] = $count;
	$g_show["list"] = $list;
	
	
	$max_page = page_bar::get_page_max($g_show["count"], $g_cgival["pcount"], $g_cgival["p"]);
	$page_bar_style = array(
			"curt"		=> $g_cgival["p"],
			"max"		=> $max_page,
			"key"		=> "p",
	);
	
	$g_show["page_bar"] = "<b>{$g_show["count"]}</b> 条记录&nbsp;&nbsp;第{$g_cgival["p"]}页&nbsp;共{$max_page}页&nbsp;" . page_bar::bar3($page_bar_style);
	
	$daohang[] = "<a href='/meinv/'>美女图库</a>";
	if($item["topic"])$daohang[] = "<a href='/meinv/index_".$item["topic_id"].".html'>".$item["topic"]."图库</a>";
	$daohang[] = "详细";
	$g_show["daohang"] =join(" <i>&gt;</i> ",$daohang);
	
	
	$db_taobao_goods_item = new db_taobao_goods_item();
	$tao_tuijian = $db_taobao_goods_item->get_taobao_list_by_site_id(1,10);
	
	$g_show["tao_tuijian"] = $tao_tuijian;
	
	
	
	
	$current_site_name = $config["current_site_name"];
	$page_title=  string_utf8::substr_utf8_cn_v2($item["content"],40)."_{$current_site_name}_{$item["create_nickname"]}_游戏美图";
	$g_show["page_title"] =$page_title;
	$g_show["page_keywords"]  = "{$item["topic"]},美女,美女图片,高清,写真,性感,车模,福利,诱惑,清纯";
	$g_show["page_desc"] = $item["content"];
	
	//右侧推荐
	$tuijian_right = mod_mblog::get_right_tuijian($config["current_site_id"],$item["create_time"]);
	$g_show["gonglue_list1"] = $tuijian_right["gonglue_list1"];
	$g_show["gonglue_list2"] =  $tuijian_right["gonglue_list2"];
	$g_show["meinv_tuijian_list"] = $tuijian_right["meinv_tuijian_list"];
	
}

try {
	$g_show['error'] = 0;
	$g_show['errmsg'] = "";
	check_cgi_pro();
	get_data();
	
	$g_show["hide_shadow"] = true;
	
} catch (Exception $e) {
	$g_show['error'] = 1;
	$g_show['errmsg'] = $e->getMessage();
}

show_pro();


exit;

function show_pro()
{
	global $g_cgival, $g_pro, $g_show, $config;

	$smarty = p_get_smarty();	
	$smarty->assign("g_show", $g_show);
	if (isset($_GET["debug"]))
	{
		print_r($g_show);
	}
	$smarty->display("meinv/detail.html");
	
	unset($g_cgival);
	unset($g_pro);
	unset($g_show);
	unset($config);
	
}

